package com.controller;

import com.pojo.Student;
import com.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@CrossOrigin
@Controller
@RequestMapping("/student")
public class StudentController {
    @Autowired
    StudentService studentService;
    public static final int PAGE_SIZE = 5;
    @GetMapping("/findAll")
    public @ResponseBody List<Student> findAll(Integer id,Integer page){
        int startRow = 0;
        if(page != null){
            startRow = (page-1)*PAGE_SIZE;
        }
        return studentService.selectFindAll(id,startRow,PAGE_SIZE);
    }

    @GetMapping("/selectById")
    public @ResponseBody List<Student> selectById(Integer id){
        return studentService.IfSelect(id);
    }

    @GetMapping("/getCount")
    public @ResponseBody int getCount(){
        return studentService.getCount();
    }

    @GetMapping("/getNoClass")
    public @ResponseBody List<Student> getNoClass(){
        return studentService.NoClass();
    }

    @RequestMapping("/getUpdateId")
    public @ResponseBody int getUpdateId(int [] stuId,int claId){
        return studentService.updateClass(stuId,claId);
    }

}
